package com.example.guiguiapplicatio.fragment.followup.adapter;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.example.guiguiapplicatio.R;
import com.example.guiguiapplicatio.Response.Record;
import com.example.guiguiapplicatio.databinding.FragmentNewFollowUpRecyItemBinding;


import java.util.List;

public class NewFollowUpFragmentAdapter  extends RecyclerView.Adapter<NewFollowUpFragmentAdapter.ViewHolder>{

        private final List<Record> mValues;
        private NavController navController;

        public NewFollowUpFragmentAdapter(List<Record> mValues) {
            this.mValues = mValues;
        }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            navController=Navigation.findNavController(parent);
        return new NewFollowUpFragmentAdapter.ViewHolder(FragmentNewFollowUpRecyItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            final int mPosition=position;
        holder.mItem=mValues.get(position);
        holder.binding.itemIdcard.setText(mValues.get(position).getIdcard());
        holder.binding.itemName.setText(mValues.get(position).getName());
        holder.binding.itemSex.setText(mValues.get(position).getSex());
        holder.binding.itemPhone.setText(mValues.get(position).getPhone());
        holder.binding.itemAdress.setText(mValues.get(position).getDetailedresidence());


        holder.binding.recyItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle =new Bundle();
                bundle.putSerializable("Record", mValues.get(mPosition));
                navController.navigate(R.id.action_newFollowUpFragment_to_classifyFragment,bundle);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mValues.size();
    }

        public class ViewHolder extends RecyclerView.ViewHolder {
            FragmentNewFollowUpRecyItemBinding binding;
            public Record mItem;
            public ViewHolder(@NonNull FragmentNewFollowUpRecyItemBinding binding) {
                super(binding.getRoot());
                this.binding=binding;
            }
        }
    }
